<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        html, body {
            height: 100%
        }
    </style>
</head>
<body>
<script src="js/echarts.min.js"></script>
<script src="js/jq.js"></script>
<div id="main" style="width: 100%;height: 50%;border: 1px solid #00FFFF"></div>
<script type="text/javascript">
    //基于准备好的dom初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'));
    //指定图表的配置项和数据
    var option = {
        title: {
            text: "ECharts 入门示例"
        },
        tooltip: {},
        legend: {
            data: ['销量']
        },
        xAxis: {
            data: []
        },
        yAxis: {},
        series: [{
            name: '销量',
            type: "bar",
            data: []
        }]
    };
    //先生成一个空的图表。
    myChart.setOption(option);
    //然后通过异步方式去读取数据，然后在回调中再次渲染图表
    $.ajax({
        url:'getChartsData.php',
        dataType:'json',
        success:function (data){
            if(data.code == 200){
                //渲染图表
                myChart.setOption({
                    xAxis: {
                        data: data.xAxis
                    },
                    series: [{
                        data: data.series
                    }]
                });
            }
            else{
                alert(data.msg);
            }
        },
        error:function (){
            alert('网络错误');
        }
    })
</script>

</body>
</html>